package canss.webservice.controls;

import org.apache.beehive.controls.api.bean.Control;
import org.apache.beehive.controls.api.bean.ControlImplementation;

import weblogic.jdbc.SQLExceptionWrapper;
import canss.encoder.DBStringEncoder;
import canss.webservice.model.ContentsChannelHolds;

import java.io.Serializable;

@ControlImplementation
public class ContentsChannelHoldsControlImpl implements
		ContentsChannelHoldsControl, Serializable
{
	private static final long serialVersionUID = 2844743122500303429L;

	@Control
	private BusinessSystemDB businesssystemDB;

	private void DB2Server(ContentsChannelHolds _cch)
	{
		_cch.setFILTER_RULE(DBStringEncoder.DB2Server(_cch.getFILTER_RULE()));
		_cch.setTBLCHANNEL_TBLPID_PID(DBStringEncoder.DB2Server(_cch
				.getTBLCHANNEL_TBLPID_PID()));
	}

	public ContentsChannelHolds[] getEntireContentsChannelHolds()
			throws SQLExceptionWrapper
	{
		ContentsChannelHolds[] ret = businesssystemDB
				.getEntireContentsChannelHolds();
		if (ret == null)
			return null;
		for (ContentsChannelHolds cch : ret)
			DB2Server(cch);
		return ret;
	}

	public ContentsChannelHolds[] getContentsChannelHoldsByPID(
			String _tblChannel_tblPID_pid) throws SQLExceptionWrapper
	{
		ContentsChannelHolds[] ret = businesssystemDB
				.getContentsChannelHoldsByPID(DBStringEncoder
						.Server2DB(_tblChannel_tblPID_pid));
		if (ret == null)
			return null;
		for (ContentsChannelHolds cch : ret)
			DB2Server(cch);
		return ret;
	}

	public ContentsChannelHolds[] getContentsChannelHoldsByPIDIndex(
			String _tblChannel_tblPID_pid, Integer _tblChannel_index_2)
			throws SQLExceptionWrapper
	{
		ContentsChannelHolds[] ret = businesssystemDB
				.getContentsChannelHoldsByPIDIndex(DBStringEncoder
						.Server2DB(_tblChannel_tblPID_pid), _tblChannel_index_2);
		if (ret == null)
			return null;
		for (ContentsChannelHolds cch : ret)
			DB2Server(cch);
		return ret;
	}

	public Boolean addNewChannelHolds(String _tblChannel_tblPID_pid,
			Integer _tblChannel_index_2) throws SQLExceptionWrapper
	{
		int ret = businesssystemDB.addNewChannelHolds(DBStringEncoder
				.Server2DB(_tblChannel_tblPID_pid), _tblChannel_index_2);
		return ret > 0;
	}

	public Boolean editFilterRuleToChannel(String _tblChannel_tblPID_pid,
			Integer _tblChannel_index_2, String _filter_rule)
			throws SQLExceptionWrapper
	{
		int ret = businesssystemDB.editFilterRuleToChannel(DBStringEncoder
				.Server2DB(_tblChannel_tblPID_pid), _tblChannel_index_2,
				DBStringEncoder.Server2DB(_filter_rule));
		return ret > 0;
	}

	public Boolean removeFilterRuleFromChannel(String _tblChannel_tblPID_pid,
			Integer _tblChannel_index_2) throws SQLExceptionWrapper
	{
		int ret = businesssystemDB.removeFilterRuleFromChannel(DBStringEncoder
				.Server2DB(_tblChannel_tblPID_pid), _tblChannel_index_2);
		return ret > 0;
	}

	public Boolean removeChannelHoldsByPIDIndex(String _tblChannel_tblPID_pid,
			Integer _tblChannel_index_2) throws SQLExceptionWrapper
	{
		int ret = businesssystemDB.removeChannelHoldsByPIDIndex(DBStringEncoder
				.Server2DB(_tblChannel_tblPID_pid), _tblChannel_index_2);
		return ret > 0;
	}
}